#ifndef GAMELOGIC_LEVEL_TILE_H_
#define GAMELOGIC_LEVEL_TILE_H_

#include <map>
#include <Ogre.h>
#include "../Objects/GameObject.h"
namespace GameLogic {
namespace Level {

class Tile {
public:
	typedef std::map< Objects::GameObject::IdType, Objects::GameObject* > MapType;
	typedef std::pair< Objects::GameObject::IdType, Objects::GameObject* > MapPair;
	typedef MapType::iterator MapIter;
	enum TileSide { tsLeft, tsRight, tsTop, tsBottom, tsWhole };
private:
	float size_;
	float x1_,y1_,x2_,y2_;
	bool enterable_;
	bool enterable_left_,enterable_right_,enterable_top_,enterable_bottom_;
	MapType pinned_objects_;
	Ogre::SceneNode* scene_node_;
public:

	static Tile* EMPTY;

	Tile():
		enterable_( false ),
		scene_node_( 0 )
	{}

	Tile(
		Ogre::SceneNode* scene_node,
		bool enterable_left = true,
		bool enterable_right = true,
		bool enterable_top = true,
		bool enterable_bottom = true
	);

	/* Wolane po dodaniu Tile'a do TileMapy. Metoda przygotowuje Tile do pracy. */
	void onInsert( int x, int y, float size );

	/* Przypina obiekt do tile'a. */
	void pin( Objects::GameObject* go ) {
		pinned_objects_.insert( MapPair( go->getId(), go ) );
	}

	/* Odpina obiekt od tile'a. */
	void unpin( Objects::GameObject* go ) {
		pinned_objects_.erase( go->getId() );
	}

	MapIter firstObject() {
		return pinned_objects_.begin();
	}

	MapIter lastObject() {
		return pinned_objects_.end();
	}

	bool isEnterable( TileSide ts ) {
		switch( ts ) {
		case tsLeft:
			return enterable_left_;
		case tsRight:
			return enterable_right_;
		case tsTop:
			return enterable_top_;
		case tsBottom:
			return enterable_bottom_;
		case tsWhole:
			return enterable_;
		default:
			return false;
		}
	}

};



} //namespace Level
} //namespace GameLogic

#endif /* GAMELOGIC_LEVEL_TILE_H_ */
